/*
  模拟常用高阶函数: map every some
*/

const map = (array, fn) => {
  const result = []
  for (const value of array) {
    result.push(fn(value))
  }
  return result
}

// Test
// let arr = [1, 2, 3, 4]
// arr = map(arr, (v) => v * v)
// console.log(arr)

const every = (array, fn) => {
  let result = true
  for (const value of array) {
    result = fn(value)
    if (!result) {
      break
    }
  }
  return result
}

// const arr = [5, 6, 7]
// const result = every(arr, (v) => v > 4)
// console.log(result)

const some = (array, fn) => {
  let result = false
  for (const value of array) {
    result = fn(value)
    if (result) {
      break
    }
  }
  return result
}
const arr = [4, 5, 9]
const result = some(arr, (v) => v > 10)
console.log(result)
